home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / comm1 / s342q12.lha / logedit.c < prev    next >
C/C++ Source or Header  |  1994-11-15  |  10KB  |  398 lines

  1. /*
  2. *                Logedit.c
  3. *
  4. * Log editor for Citadel-86, V 2.x.
  5. */
  6. /*
  7. *                history
  8. *
  9. * 89Apr16 HAW  New visual support for PC Clones.  (non-portable)
  10. * 87Oct11 HAW  V3 update.
  11. * 85Nov16 HAW  Modified for MS-DOS libraries.
  12. * 85Aug10 HAW  Created.
  13. */
  14. #include "ctdl.h"    /* header file  */
  15. #include <stdio.h>
  16. #include <string.h>
  17. #include <stdlib.h>
  18. #include <math.h>
  19. #include <ctype.h>
  20. #include <time.h>
  21. #include <proto/exec.h>
  22. #include <dos/dos.h>
  23. #include <pragmas/dos_pragmas.h>
  24. #include "exec/memory.h"
  25. #include "exec/ports.h"
  26. #include "exec/exec.h"
  27. /*
  28. *                Contents
  29. *
  30. *    crashout()        irrecoverable error
  31. *    getUNumber()        Gets number from console
  32. *    getUtilString()        Gets string from console
  33. *    logSum()        Sums up the log for logTab
  34. *    main()            Main controller
  35. */
  36. char NoShow = FALSE;
  37. extern CONFIG    cfg;
  38. extern SListBase MailForward;
  39. extern LogTable    *logTab;     /* RAM index of pippuls    */
  40. extern logBuffer logBuf;     /* Pippul buffer    */
  41. extern FILE    *logfl;       /* log file descriptor    */
  42. extern int    thisLog;
  43. void getUtilString(char *prompt, char *buf, int lim);
  44. void logSum(void);
  45. void crashout ( char *str );
  46. void handleEditing ( void );
  47. int getUNumber ( char *prompt , unsigned bottom , unsigned top );
  48. void getUtilString ( char *prompt , char *buf , int lim );
  49. int logSort ( LogTable *s1 , LogTable *s2 );
  50. int main ( int argc , char **argv );
  51. void showlog ( void );
  52. void Display_Flag (short,short, char *);
  53.  
  54. /*
  55. * crashout()
  56. *
  57. * This handles an irrecoverable error.
  58. */
  59. void crashout(str)
  60. char *str;
  61.   {
  62.   printf(str);
  63.   exit(10);
  64.  
  65.   }
  66. /*
  67. * handleEditing()
  68. *
  69. * This handles editing accounts in a very primitive manner.
  70. */
  71. void handleEditing()
  72.   {
  73.   char c;
  74.   char mess[40];
  75.   int account;
  76.   label NewName;
  77.   logBuffer lBuf;
  78.   ForwardMail *data;
  79.   initLogBuf(&lBuf);
  80.   sPrintf(mess, "Which account (%d to quit): ", cfg.MAXLOGTAB);
  81.   account = getUNumber(mess, 0, cfg.MAXLOGTAB);
  82.   getLog(&logBuf, account);
  83.   while (account != cfg.MAXLOGTAB)
  84.     {
  85.     showlog();
  86.     printf("LogEdit Menu\n");
  87.     printf("A - toggle Active Acct   \t S - toggle Aide Status\n");
  88.     printf("E - toggle Expert mode   \t N - toggle Net Privileges\n");
  89.     printf("D - toggle Door Privs    \t L - toggle Download Privileges\n");
  90.     printf("B - toggle Permanent Acct\t F - toggle Floor mode\n");
  91.     printf("T - toggle Twit Status   \t R - toggle Ruggie Status\n");
  92.     printf("C - change user name     \t P - change user password\n");
  93.     printf("W - change column width  \t G - Go to New account\n");
  94.     printf(" Q - Quit\n");
  95.     c = getchar();
  96.     while( getchar() != '\n');
  97.     switch( c )
  98.       {
  99.       case 'w':
  100.       case 'W':
  101.       sprintf(mess,"Enter new column width(40-80):");
  102.       logBuf.lbwidth = getUNumber(mess,40,80);
  103.       putLog(&logBuf, account);
  104.       break;
  105.       case 'g':
  106.       case 'G': /* go to next account */
  107.       sPrintf(mess, "Which account (%d to quit): ", cfg.MAXLOGTAB);
  108.       account = getUNumber(mess, 0, cfg.MAXLOGTAB);
  109.       getLog(&logBuf, account);
  110.       break;
  111.       case 'a':
  112.       case 'A': /* activate an account */
  113.       if (logBuf.lbflags.L_INUSE != 1)
  114.         {
  115.         logBuf.lbflags.L_INUSE = 1;
  116.  
  117.         }
  118.       else
  119.         {
  120.         logBuf.lbflags.L_INUSE = 0;
  121.         if (SearchList(&MailForward, logBuf.lbname) != NULL)
  122.           {
  123.           KillData(&MailForward, logBuf.lbname);
  124.           UpdateForwarding();
  125.  
  126.           };
  127.  
  128.         };
  129.       putLog(&logBuf, account);
  130.       break;
  131.       case 'q' :
  132.       case 'Q' :  /* Quit */
  133.       return;
  134.       break;
  135.       case 'C' :  /* Change a User's name */
  136.       case 'c' :
  137.       getUtilString("new name", NewName, NAMESIZE);
  138.       if (strLen(NewName) != 0)
  139.         {
  140.         if (findPerson(NewName, &lBuf) != ERROR)
  141.           {
  142.           printf("%s already in use.\n", NewName);
  143.  
  144.           }
  145.         else
  146.           {
  147.           if ((data = SearchList(&MailForward,logBuf.lbname)) != NULL)
  148.             {
  149.             data->UserName = strdup(NewName);
  150.             KillData(&MailForward, logBuf.lbname);
  151.             UpdateForwarding();
  152.  
  153.             };
  154.           strCpy(logBuf.lbname, NewName);
  155.           putLog(&logBuf, account);
  156.  
  157.           };
  158.  
  159.         }
  160.       else printf("No name entered, aborted change\n");
  161.       break;
  162.       case 'S' :
  163.       case 's' :
  164.       logBuf.lbflags.AIDE =  (logBuf.lbflags.AIDE) ? 0 : 1;
  165.       putLog(&logBuf, account);
  166.       break;
  167.       case 'E' :
  168.       case 'e' :
  169.       logBuf.lbflags.EXPERT   = logBuf.lbflags.EXPERT ? 0 : 1;
  170.       putLog(&logBuf, account);
  171.       break;
  172.       case 'N' :
  173.       case 'n' :
  174.       logBuf.lbflags.NET_PRIVS= logBuf.lbflags.NET_PRIVS ? 0 : 1;
  175.       putLog(&logBuf, account);
  176.       break;
  177.       case 'D' :
  178.       case 'd' :
  179.       logBuf.lbflags.DOOR_PRIVS = logBuf.lbflags.DOOR_PRIVS ? 0 : 1;
  180.       putLog(&logBuf, account);
  181.       break;
  182.       case 'L' :
  183.       case 'l' :
  184.       logBuf.lbflags.DL_PRIVS = logBuf.lbflags.DL_PRIVS ? 0 : 1;
  185.       putLog(&logBuf, account);
  186.       break;
  187.       case 'B' :
  188.       case 'b' :
  189.       logBuf.lbflags.PERMANENT= logBuf.lbflags.PERMANENT ? 0 : 1;
  190.       putLog(&logBuf, account);
  191.       break;
  192.       case 'F' :
  193.       case 'f' :
  194.       logBuf.lbflags.FLOORS   = logBuf.lbflags.FLOORS ? 0 : 1;
  195.       putLog(&logBuf, account);
  196.       break;
  197.       case 'T' :
  198.       case 't' :
  199.       logBuf.lbflags.TWIT     = logBuf.lbflags.TWIT   ? 0 : 1;
  200.       putLog(&logBuf, account);
  201.       break;
  202.       case 'R' :
  203.       case 'r' :
  204.       logBuf.lbflags.RUGGIE   = logBuf.lbflags.RUGGIE ? 0 : 1;
  205.       putLog(&logBuf, account);
  206.       break;
  207.       Default:  printf("Invalid function Choice\n");
  208.  
  209.       };
  210.  
  211.     };
  212.   /* Loop until User enters Quit */
  213.  
  214.   }
  215. /*
  216. * getUNumber()
  217. *
  218. * This prompts for a number in (bottom, top) range.
  219. */
  220. int getUNumber(prompt, bottom, top)
  221. char   *prompt;
  222. unsigned bottom;
  223. unsigned top;
  224.   {
  225.   unsigned try;
  226.   char numstring[NAMESIZE];
  227.   do
  228.     {
  229.     getUtilString(prompt, numstring, NAMESIZE);
  230.     try     = atoi(numstring);
  231.     if (try < bottom)  printf("Sorry, must be at least %d\n", bottom);
  232.     if (try > top   )  printf("Sorry, must be no more than %d\n", top);
  233.  
  234.     }
  235.   while (try < bottom ||  try > top);
  236.   return (int)try;
  237.  
  238.   }
  239. /*
  240. * getUtilString()
  241. *
  242. * This function gets a string from the user.
  243. */
  244. void getUtilString(prompt, buf, lim)
  245. char *prompt;
  246. char *buf;
  247. int  lim;       /* max # chars to read */
  248.   {
  249.   char *c;
  250.   short x;
  251.   printf("Enter %s:", prompt, lim);
  252.   c = fgets(buf,lim,stdin);
  253.   for(x=0; x<lim;x++)if( buf[x] == '\n')buf[x] = '\0';
  254.   printf("\n");
  255.  
  256.   }
  257. /*
  258. * logSort()
  259. *
  260. * This is used for sorting the log.
  261. */
  262. int logSort(s1, s2)
  263. LogTable *s1, *s2;
  264.   {
  265.   if (s1->ltnmhash == 0 && s2->ltnmhash == 0)
  266.   return 0;
  267.   if (s1->ltnmhash == 0 && s2->ltnmhash != 0)
  268.   return 1;
  269.   if (s1->ltnmhash != 0 && s2->ltnmhash == 0)
  270.   return -1;
  271.   if (s1->ltnewest < s2->ltnewest)
  272.   return 1;
  273.   if (s1->ltnewest > s2->ltnewest)
  274.   return -1;
  275.   return 0;
  276.  
  277.   }
  278. /*
  279. * logSum()
  280. *
  281. * This goes through the log to correct logTab.
  282. */
  283. void logSum()
  284.   {
  285.   int i;
  286.   int logSort();
  287.   int count = 0;
  288.   #ifdef WORKS
  289.   if (rewind(logfl) != 0) crashout("Rewinding logfl failed!");
  290.   #else
  291.   rewind(logfl);
  292.   #endif
  293.   /* clear logTab */
  294.   for (i = 0;i < cfg.MAXLOGTAB;i++) logTab[i].ltnewest = 0l;
  295.   /* load logTab: */
  296.   for (thisLog = 0;thisLog < cfg.MAXLOGTAB;thisLog++)
  297.     {
  298.     getLog(&logBuf, thisLog);
  299.     /* count valid entries:    */
  300.     if (logBuf.lbflags.L_INUSE)
  301.       {
  302.       if (strLen(logBuf.lbname) >= NAMESIZE ||
  303.       strLen(logBuf.lbpw) >= NAMESIZE )
  304.         {
  305.         logBuf.lbflags.L_INUSE = FALSE;
  306.         putLog(&logBuf, thisLog);
  307.  
  308.         }
  309.       else
  310.         {
  311.         count++;
  312.  
  313.         }
  314.  
  315.       };
  316.     /* copy relevant info into index:   */
  317.     logTab[thisLog].ltnewest = logBuf.lbvisit[0];
  318.     logTab[thisLog].ltlogSlot= thisLog;
  319.     if (logBuf.lbflags.L_INUSE == 1)
  320.       {
  321.       logTab[thisLog].ltnmhash = hash(logBuf.lbname);
  322.       logTab[thisLog].ltpwhash = hash(logBuf.lbpw  );
  323.       logTab[thisLog].ltpermanent = logBuf.lbflags.PERMANENT;
  324.  
  325.       }
  326.     else
  327.       {
  328.       logTab[thisLog].ltnmhash = 0;
  329.       logTab[thisLog].ltpwhash = 0;
  330.  
  331.       }
  332.  
  333.     }
  334.   printf(" logInit--%d valid log entries\n", count);
  335.   qsort((char *)logTab, cfg.MAXLOGTAB, cfg.sizeLTentry, logSort);
  336.  
  337.   }
  338. /*
  339. * main()
  340. *
  341. * Main controller.
  342. */
  343. main(argc, argv)
  344. int argc;
  345. char **argv;
  346.   {
  347.   SYS_FILE logfile;
  348.   printf("LOGEDIT V3.42\n%s\n", COPYRIGHT);
  349.   cfg.weAre = UTILITY;
  350.   if (!readSysTab(FALSE, TRUE)) exit(1);
  351.   if (access(LOCKFILE, 0) != -1)
  352.     {
  353.     printf("Please do not run LogEdit from Outside Commands.\n");
  354.     writeSysTab();
  355.     exit(1);
  356.  
  357.     }
  358.   makeSysName(logfile, "ctdllog.sys", &cfg.logArea);
  359.   openFile(logfile, &logfl);
  360.   initLogBuf(&logBuf);
  361.   makeSysName(logfile, "ctdlfwd.sys", &cfg.roomArea);
  362.   MakeList(&MailForward, logfile, NULL);
  363.   handleEditing();
  364.   logSum();
  365.   writeSysTab();
  366.   return 0;
  367.   }
  368. void showlog()
  369.   {
  370.   char *LastOn(long lastdate, char s);
  371.   printf(" %-20s",logBuf.lbname);
  372.   printf("%8ld", logBuf.lbvisit[0]);
  373.   printf(" %d columns. Date:%s\n",logBuf.lbwidth,LastOn(logBuf.lblaston, TRUE));
  374.   Display_Flag(0,logBuf.lbflags.AIDE       ,"AIDE Status        ");
  375.   Display_Flag(1,logBuf.lbflags.EXPERT     ,"Expert User        ");
  376.   Display_Flag(0,logBuf.lbflags.NET_PRIVS  ,"Network Privileges ");
  377.   Display_Flag(1,logBuf.lbflags.DOOR_PRIVS ,"Door Privileges    ");
  378.   Display_Flag(0,logBuf.lbflags.DL_PRIVS   ,"Download Privileges");
  379.   Display_Flag(1,logBuf.lbflags.PERMANENT  ,"Permanent Account  ");
  380.   Display_Flag(0,logBuf.lbflags.FLOORS     ,"Floor mode         ");
  381.   Display_Flag(1,logBuf.lbflags.TWIT       ,"TWIT User          ");
  382.   Display_Flag(0,logBuf.lbflags.RUGGIE     ,"RUGGIE User        ");
  383.   Display_Flag(1,logBuf.lbflags.L_INUSE    ,"Active Account     ");
  384.   Display_Flag(0,logBuf.lbflags.LFMASK     ,"LF FLAG            ");
  385.   Display_Flag(1,logBuf.lbflags.OLDTOO     ,"OLD STYLE          ");
  386.   Display_Flag(0,logBuf.lbflags.HALF_DUP   ,"HALF DUPLEX        ");
  387.   Display_Flag(1,logBuf.lbflags.ALT_RE     ,"ALT. Read Messages ");
  388.   Display_Flag(0,logBuf.lbflags.NoPrompt   ,"Room Name Prompt   ");
  389.   printf("\n");
  390.   }
  391. void Display_Flag(flag,bit,text)
  392. short  flag, bit;
  393. char  *text;
  394.   {
  395.   printf(" %s: %s%c",text,(bit ? "Yes" : "No "), (flag==0 ? '\t':'\n'));
  396.  
  397.   }
  398.